// function Hunter (name, level){
//     this.name = name;
//     this.level = level;
//     this.list = []
// }
// Hunter.prototype.publish = function(money){
//     console.log(this.level + '猎人' + this.name + '寻求帮助')
//     this.list.forEach(item=>{
//         item(money)
//     })
// }
// Hunter.prototype.subscribe = function(target ,fn){
//     console.log(this.level + '猎人' + this.name + '订阅了' + target.name)
//     target.list.push(fn)
// }
class Hunter {
    constructor(name, level) {
        this.name = name
        this.level = level
        this.list = []
    }
    publish(money) {
        console.log(this.level + '猎人' + this.name + '寻求帮助')
        this.list.forEach(item => {
            item(money)
        })
    }
    subscribe(target, fn) {
        console.log(this.level + '猎人' + this.name + '订阅了' + target.name)
        target.list.push(fn)
    }
}


let hunterMing = new Hunter('小明', '黄金')
let hunterJin = new Hunter('小金', '白银')
let hunterZhang = new Hunter('小张', '黄金')
let hunterPeter = new Hunter('Peter', '青铜')


hunterMing.subscribe(hunterPeter, function (money) {
    console.log('小明表示：' + (money > 200 ? '' : '暂时很忙，不能') + '给予帮助')
})
hunterJin.subscribe(hunterPeter, function () {
    console.log('小金表示：给予帮助')
})
hunterJin.subscribe(hunterMing, function () {
    console.log('小金表示：给予帮助')
})
hunterZhang.subscribe(hunterPeter, function () {
    console.log('小张表示：给予帮助')
})

//Peter遇到困难，赏金198寻求帮助
hunterPeter.publish(198)
hunterMing.publish(200)